﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
namespace ConsoleApplication7
{
	public class CC1{
		public static void log(){
			foreach (string element in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory+"config//","*.xml",SearchOption.TopDirectoryOnly)) {
			         	if (element.Contains("xml.xml")) {
					continue;
				}
			         	XmlDocument doc=new XmlDocument();
			         	doc.Load(element);
			    XmlNodeList list=     	doc.DocumentElement.SelectNodes("item");
			    if (list!=null) {
			    	StringBuilder html=new StringBuilder();
			    	foreach (  XmlNode el in list) {
			    		html.AppendFormat(@" copy |{0}| |@@| "+"\r\n",el.ParentNode.Attributes["path"].Value+el.Attributes["name"].Value);
			    	}
			    	Clog.Write("xx.bat",html.ToString());
			    }
			}
		}
	}
    public  class Clog
    {
        public static void Write2(string filename, string _logContent)
        {
            String FileName = "ServiceLog_" + DateTime.Now.ToString("yyyy-MM-ddhh") + filename + ".log";
            String strFolderPath = System.AppDomain.CurrentDomain.BaseDirectory + @"\LogFiles\";
            if (!Directory.Exists(strFolderPath))
                Directory.CreateDirectory(strFolderPath);

            string strPath = strFolderPath + @"\" + FileName;
            if (File.Exists(strPath))
            {
                FileInfo f = new FileInfo(strPath);
                if (f.Length / 1048576 > 0)
                {
                    strPath = strFolderPath + @"\" + (Directory.GetFiles(strFolderPath).ToArray().Length + 1).ToString() + FileName;
                }
            }
            FileStream fs = new FileStream(strPath, FileMode.OpenOrCreate, FileAccess.Write);

            StreamWriter m_streamWriter = new StreamWriter(fs);
            m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
            m_streamWriter.WriteLine("发生时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ";日志内容：" + _logContent);
            m_streamWriter.Flush();
            m_streamWriter.Close();
            fs.Close();
        }
        public static void Write(string filename, string _logContent)
        {
            String FileName = DateTime.Now.ToString("yyyy-MM-dd") + filename + ".log";
            String strFolderPath = System.AppDomain.CurrentDomain.BaseDirectory + @"\error\";
            if (!Directory.Exists(strFolderPath))
                Directory.CreateDirectory(strFolderPath);

            string strPath = strFolderPath + @"\" + FileName;
            if (File.Exists(strPath))
            {
                FileInfo f = new FileInfo(strPath);
                if (f.Length / 1048576 > 0)
                {
                    strPath = strFolderPath + @"\" + (Directory.GetFiles(strFolderPath).ToArray().Length + 1).ToString() + FileName;
                }
            }
            FileStream fs = new FileStream(strPath, FileMode.OpenOrCreate, FileAccess.Write);

            StreamWriter m_streamWriter = new StreamWriter(fs);
            m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
            m_streamWriter.WriteLine(_logContent);
            m_streamWriter.Flush();
            m_streamWriter.Close();
            fs.Close();
        }
    }
}
